<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="${pageContext.request.contextPath}/include/pageTitleBread.jsp"/>
<div id="page-content">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title">${pageInfo.innerTitle}</h3>
            </div>
            <form id="goodsInfoForm" class="panel-body form-horizontal form-padding">
                <div class="form-group">
                    <label class="col-sm-3 control-label">所属分类：</label>
                    <div class="col-sm-5">
                        <select name="flCategory" id="flCategory" class="form-control">
                            <option value="-1">测试</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品名称：</label>
                    <div class="col-sm-5">
                        <input id="flName" name="flName" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品缩略图：</label>
                    <div class="col-sm-5">
                        <input id="flThumbnailPic" name="flThumbnailPic" type="hidden">
                        <input id="file" name="file" class="form-control" type="file">
                        <small class="help-block">*建议图片为50*50</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品轮播图：</label>
                    <div class="col-sm-5">
                        <input id="flRotationPic" name="flRotationPic" type="hidden">
                        <input id="file1" name="file" class="form-control" type="file">
                        <small class="help-block">*建议图片为250*250,数量3到5张</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品详情：</label>
                    <div class="col-sm-8">
                        <input id="flDetail" name="flDetail" type="hidden">
                        <span id="detail" name="detail" class="form-control"></span>
                        <small class="help-block">*手机格式进行排版</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品原价：</label>
                    <div class="col-sm-5">
                        <input id="flOriginalPrice" name="flOriginalPrice" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品销售价格：</label>
                    <div class="col-sm-5">
                        <input id="flSalePrice" name="flSalePrice" class="form-control" type="text">
                        <small class="help-block">*真实的销售价格</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">关联客户：</label>
                    <div class="col-sm-5">
                        <select name="flCstId" id="flCstId" class="form-control">
                            <option value="-1">平台</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">剩余库存：</label>
                    <div class="col-sm-5">
                        <input id="flStock" name="flStock" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">是否启用商品分销模式：</label>
                    <div class="col-sm-5">
                        <input id="fl_type_ml" class="magic-radio" type="radio" name="flIsEnableGoodsDis"
                               value="0">
                        <label for="fl_type_ml">禁用</label>
                        <input id="fl_type_cd" class="magic-radio" type="radio" name="flIsEnableGoodsDis"
                               value="1" checked>
                        <label for="fl_type_cd">启用</label>
                        <small class="help-block">*如果选择禁用默认使用系统分润模式</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">一级会员分润：</label>
                    <div class="col-sm-5">
                        <input id="flFirstProfit" name="flFirstProfit" class="form-control" type="text"
                               placeholder="这里填写真实的分润金额">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">二级会员分润：</label>
                    <div class="col-sm-5">
                        <input id="flSecondProfit" name="flSecondProfit" class="form-control" type="text"
                               placeholder="这里填写真实的分润金额">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">三级会员分润：</label>
                    <div class="col-sm-5">
                        <input id="flThirdProfit" name="flThirdProfit" class="form-control" type="text"
                               placeholder="这里填写真实的分润金额">
                    </div>
                </div>
                <div class="panel-footer">
                    <div class="row">
                        <div class="col-sm-9 col-sm-offset-3">
                            <button class="btn btn-warning" type="reset">重置</button>
                            <button class="btn btn-mint" type="submit">保存</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>

    function save() {
        var content = $("#detail").summernote('code');
        $("#flDetail").val(content);
        var data = common_ajax.ajaxFunc("/goodsInfo/saveOrUpdate", $('#goodsInfoForm').serialize(), "json", null);
        if (data.code === 0) {
            pointLion.alertMsg("保存成功!", "success", "small", function () {
                doPjax(ctx + '/goodsInfo');//跳转到列表页
            });
        } else {
            pointLion.alertMsg("操作失败!", "danger", "small", function () {
                doPjax(ctx + '/goodsInfo');//跳转到列表页
            });
        }
    }

    $(document).ready(function () {
        common_ajax.initFileUpload("file", "${pageContext.request.contextPath}/commons/upload", "flThumbnailPic", 1);
        common_ajax.initFileUpload("file1", "${pageContext.request.contextPath}/commons/upload", "flRotationPic", 5);
        common_ajax.initCombo("flCstId","${pageContext.request.contextPath}/cstInfo/initCombo",-1);
        common_ajax.initCombo("flCategory","${pageContext.request.contextPath}/categoryInfo/initCombo",-1);
        $('#detail').summernote({
            toolbar: [
                ['style', ['style','bold', 'italic', 'underline', 'clear']],
                ['font', ['strikethrough', 'superscript', 'subscript']],
                ['fontname', ['fontname']],
                ['fontsize', ['fontsize']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']],
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['codeview','fullscreen']]
            ],
            lang : 'zh-CN',
            dialogsFade : true,
            dialogsInBody : true,
            disableDragAndDrop : false,
            minHeight : '500px'
        });
        $('#goodsInfoForm').bootstrapValidator({
            excluded: [":hidden"],//关键配置，表示只对于隐藏域不进行验证，其他的表单元素都要验证
            fields: {
                "fl_code": {
                    validators: {
                        notEmpty: {
                            message: '*XXXX不能为空!'
                        },
                        stringLength: {
                            min: 2,
                            message: '*XXXX必须大于两位'
                        }
                    }
                },
                "fl_name": {
                    validators: {
                        notEmpty: {
                            message: '*XXXX不能为空'
                        },
                        stringLength: {
                            min: 2,
                            message: '*XXXX必须大于两位'
                        }
                    }
                }
            }
        }).on("success.form.bv", function (e) {
            save();
            return false;//阻止表单跳转
        });
    });
</script>
